﻿using Logistics.Remit;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Logistics.Web.Controllers
{
    public class PaymentController : Controller
    {
        private readonly PaymentAppService _paymentAppService;
        public PaymentController(PaymentAppService paymentAppService)
        {
            _paymentAppService = paymentAppService;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task Delete(int id)
        {
            var i = _paymentAppService.DeleteAsync(id);
            return i;
        }
        /// <summary>
        /// 查看视图
        /// </summary>
        /// <returns></returns>
        public ActionResult ByIdIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 反填视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PutIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        public IActionResult Update(PaymentDto paymentDto)
        {
            var pay = _paymentAppService.UpdateAsync(paymentDto);
            return Ok(pay);
        }

        /// <summary>
        /// 查看详情/反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<PaymentDto> GetById(int id)
        {
            var pay = _paymentAppService.GetAsync(id);
            return pay;
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult PostIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Procurement"></param>
        /// <returns></returns>
        public IActionResult Add(PaymentDto paymentDto)
        {
            var i = _paymentAppService.CreateAsync(paymentDto).Result;
            return Ok(i);
        }
        /// <summary>
        /// 主页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult PayIndex()
        {
            return View();
        }
        // GET: ApproveController/Details/5
        public JsonResult ShowPayment(PaymentListDto paymentListDto)
        {
            var pay = _paymentAppService.GetListAsync(paymentListDto).Result;
            return Json(new { data = pay.Items, count = pay.TotalCount, code = "0", msg = "" });
        }
    }
}
